<template>
  <div class="assess">
    <Header></Header>
    <div class="assessMain">
      <div class="mianOut mt20">
        <div class="mianInner1">
          <div class="assess-title2">
            <p :class="planSummaryName?'':'noPlanClass'"><img src="../../../static/images/sound.png"/>提示信息：您收到{{planSummaryName}}，需要您进行评审工作。
            </p>
            <ul class="clearfix">
              <li class="active"
                  @click="$router.push('waitAssess')">待评审
              </li>
              <li @click="reviewedHandle">已评审</li>
            </ul>
            <h4>待评审预案</h4>
          </div>
          <el-table ref="multipleTable"
                    :data="reviewList">
            <el-table-column type="index"
                             align='center'
                             label='序号'
                             width="150">
            </el-table-column>
            <el-table-column label="评审时间"
                             align='center'
                             width='350'>
              <template slot-scope="scope">
                <p><span>{{scope.row.reviewStartTime | timeBy}}</span>到<span>{{scope.row.reviewEndTime | timeBy}}</span>
                </p>
              </template>
            </el-table-column>
            <el-table-column prop="planSummaryName"
                             label="评审预案任务"
                             align='center'
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="操作"
                             align='center'
                             width='250'>
              <template slot-scope="scope">
                <el-button class='detail-btn'
                           @click="goPath(scope.row)"><i class="el-icon-edit">评审</i></el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="page-container">
            <el-button>确定</el-button>
            <el-pagination :pager-count='5'
                           @current-change="handleCurrentChange"
                           :current-page="currentPage"
                           :page-size="pageSize"
                           layout="total, prev, pager, next, jumper"
                           :total="total">
            </el-pagination>
          </div>
          <div class="assess-title2">
            <h4>企业预约列表</h4>
          </div>
          <el-table ref="multipleTable1"
                    :data="reviewList1">
            <el-table-column type="index"
                             align='center'
                             label='序号'
                             width="150">
            </el-table-column>
            <el-table-column label="评审时间"
                             align='center'
                             width='350'>
              <template slot-scope="scope">
                <p>
                  <span>{{scope.row.appointStartTime | timeBy}}</span>到<span>{{scope.row.appointEndTime | timeBy}}</span>
                </p>
              </template>
            </el-table-column>
            <el-table-column prop="planSummaryName"
                             label="评审预案任务"
                             align='center'
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="状态"
              align="center"
            >
              <template slot-scope="scope">
                                        <span>{{
                                            scope.row.status | changeType
                                        }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作"
                             align='center'
                             width='250'>
              <template slot-scope="scope">
                <el-button class='detail-btn'
                           @click="goPath1(scope.row,'1')"><i class="el-icon-edit">接收</i></el-button>
                <el-button class='detail-btn'
                           @click="goPath1(scope.row,'2')"><i class="el-icon-edit">拒绝</i></el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="page-container">
            <el-button>确定</el-button>
            <el-pagination :pager-count='5'
                           @current-change="handleCurrentChange1"
                           :current-page="currentPage1"
                           :page-size="pageSize1"
                           layout="total, prev, pager, next, jumper"
                           :total="total1">
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
    <Footer/>
  </div>
</template>
<script>
  import Header from '../common/header2'
  import Footer from '../common/footer'
  import config from '../../config.js'

  export default {
    components: {
      Header,
      Footer
    },
    data() {
      return {
        reviewList: [],
        currentPage: 1,
        pageSize: 10,
        total: 0,
        planSummaryName: '',
        reviewList1: [],
        currentPage1: 1,
        pageSize1: 10,
        total1: 0,
      };
    },
    created() {
      this.getreviewList();
      this.getreviewList1()
    },

    methods: {
      goPath(row) {
        localStorage.planid = row.planSummaryId
        localStorage.planname = row.planSummaryName
        localStorage.plancompanyName = row.companyName
        this.$router.push({name: 'comAssess', query: {id: row.planSummaryId, planSummaryName: row.planSummaryName}})
      },
      goPath1(row, num) {
        if(row.status!='0'){
          this.$message.warning("已确认,无法再次操作");
          return
        }
        if(Date.parse(row.appointEndTime) < new Date()){
          this.$message.warning("已超期,无法再次操作");
          return
        }
        this.$axios
          .post(config.baseUrl + "special/v1.0/special/confirmation", {
            companyId: row.companyId,
            planSummaryId: row.planSummaryId,
            requiredTime: this.getDate(),
            status: num,
            userId: row.userId
          })
          .then(res => {
            console.log(res)
            console.log(res.data.meta.success)
            if (res.data.meta.success) {
              this.$message.success("操作成功");
              this.getreviewList1()
            } else {
              this.$message.warning(res.data.meta.message);
            }
          })
          .catch(response => {
            console.log(response);
          });
      },
      getreviewList() {
        let url = config.baseUrl + 'planreview/v1.0/planreview/querylist'
        let params = {
          "userId": JSON.parse(localStorage.getItem('user')).id,
          "current": this.currentPage,
          "size": this.pageSize,
          "status": 2
        }
        this.$axios(url, {params: params})
          .then((res) => {
            if (res.data.meta.success) {
              res.data.data.records.forEach((item) => {
                if (item.substringreviewStartTime) {
                  return item.reviewStartTime.substring(0, 10)
                }
              })
              this.reviewList = res.data.data.records
              this.total = res.data.data.total
              this.planSummaryName = res.data.data.records[0].planSummaryName.split('.docx')[0]
            } else {
              this.reviewList = []
              this.total = 0
            }
          })
      },
      getreviewList1() {
        let url = config.baseUrl + 'special/v2.0/special/receiveappoint?userId=' + JSON.parse(localStorage.getItem('user')).id + "&current=" + this.currentPage1 + "&size=" + this.pageSize1
        let params = {
          "userId": JSON.parse(localStorage.getItem('user')).id,
          "current": this.currentPage1,
          "size": this.pageSize1
        }
        this.$axios.post(url, {})
          .then((res) => {
            if (res.data.meta.success) {
              res.data.data.records.forEach((item) => {
                if (item.substringreviewStartTime) {
                  return item.reviewStartTime.substring(0, 10)
                }
              })
              this.reviewList1 = res.data.data.records
              this.total1 = res.data.data.total
              this.planSummaryName = res.data.data.records[0].planSummaryName.split('.docx')[0]
            } else {
              this.reviewList1 = []
              this.total1 = 0
            }
          })
      },
      handleCurrentChange(val) {
        this.currentPage = val
        this.getreviewList()
      },
      handleCurrentChange1(val) {
        this.currentPage1 = val
        this.getreviewList1()
      },
      getDate() {
        //时间格式化补0
        var zeroize = function (value, length) {
          if (!length) length = 2;
          value = String(value);
          for (var i = 0, zeros = ''; i < (length - value.length); i++) {
            zeros += '0';
          }
          return zeros + value;
        };
        var myDate = new Date();
        return myDate.getFullYear() + "-" + zeroize(myDate.getMonth() + 1) + "-" + zeroize(myDate.getDate());
      },
      reviewedHandle() {
        this.$router.push('assessed')
        if (this.planSummaryName) {
          this.$router.push({query: {'name': this.planSummaryName}})
        }
      }
    },
    filters: {
      changeType(val) {
        if (!val) {
          return "";
        }
        if (val == 0) {
          return "待确认";
        } else if (val == 1) {
          return "预约成功";
        } else {
          return "预约失败";
        }
      },
      timeBy(val) {
        if (val) {
          return val.substring(0, 10)
        }
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='less'>
  @import "../../../static/css/assess.less";
</style>
<style lang='less' scoped>
  .assess {
    .assess-title2 {
      .allBtn {
        display: block;
        width: 136px;
        border-radius: 8px;
        height: 36px;
        text-align: center;
        line-height: 36px;
        color: #fff;
        background: #4080ff;
        /*background: linear-gradient(90deg, #6eb1ff 20%, #3372ff 80%);*/
        float: right;
        font-weight: normal;
        font-size: 14px;
        margin-right: 100px;
        position: relative;
        top: -8px;
      }
      .allBtn:hover {
        opacity: .8;
      }
      .noPlanClass {
        opacity: 0;
        filter: alpha(opacity=0);
      }
    }
  }
</style>
